﻿using System;
using XUCore.Webs.Clients;

namespace XUCore.Webs
{

    public static class WebExtensions
    {

        /// <summary>
        /// Get请求
        /// </summary>
        /// <param name="urlBuilder"></param>
        /// <returns></returns>
        public static IHttpRequest Get(this UrlBuilder urlBuilder) => new WebClient().Get(urlBuilder.ToString());
        /// <summary>
        /// Post请求
        /// </summary>
        /// <param name="urlBuilder"></param>
        /// <returns></returns>
        public static IHttpRequest Post(this UrlBuilder urlBuilder) => new WebClient().Post(urlBuilder.ToString());
        /// <summary>
        /// Put请求
        /// </summary>
        /// <param name="urlBuilder"></param>
        /// <returns></returns>
        public static IHttpRequest Put(this UrlBuilder urlBuilder) => new WebClient().Put(urlBuilder.ToString());
        /// <summary>
        /// Delete请求
        /// </summary>
        /// <param name="urlBuilder"></param>
        /// <returns></returns>
        public static IHttpRequest Delete(this UrlBuilder urlBuilder) => new WebClient().Delete(urlBuilder.ToString());

        /// <summary>
        /// Get请求
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="urlBuilder"></param>
        /// <returns></returns>
        public static IHttpRequest<TResult> Get<TResult>(this UrlBuilder urlBuilder) where TResult : class => new WebClient<TResult>().Get(urlBuilder.ToString());
        /// <summary>
        /// Post请求
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="urlBuilder"></param>
        /// <returns></returns>
        public static IHttpRequest<TResult> Post<TResult>(this UrlBuilder urlBuilder) where TResult : class => new WebClient<TResult>().Post(urlBuilder.ToString());
        /// <summary>
        /// Put请求
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="urlBuilder"></param>
        /// <returns></returns>
        public static IHttpRequest<TResult> Put<TResult>(this UrlBuilder urlBuilder) where TResult : class => new WebClient<TResult>().Put(urlBuilder.ToString());
        /// <summary>
        /// Delete请求
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="urlBuilder"></param>
        /// <returns></returns>
        public static IHttpRequest<TResult> Delete<TResult>(this UrlBuilder urlBuilder) where TResult : class => new WebClient<TResult>().Delete(urlBuilder.ToString());

        /// <summary>
        /// Get请求
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static IHttpRequest Get(this string url) => new WebClient().Get(url);
        /// <summary>
        /// Post请求
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static IHttpRequest Post(this string url) => new WebClient().Post(url);
        /// <summary>
        /// Put请求
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static IHttpRequest Put(this string url) => new WebClient().Put(url);
        /// <summary>
        /// Delete请求
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static IHttpRequest Delete(this string url) => new WebClient().Delete(url);

        /// <summary>
        /// Get请求
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="url"></param>
        /// <returns></returns>
        public static IHttpRequest<TResult> Get<TResult>(this string url) where TResult : class => new WebClient<TResult>().Get(url);
        /// <summary>
        /// Post请求
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="url"></param>
        /// <returns></returns>
        public static IHttpRequest<TResult> Post<TResult>(this string url) where TResult : class => new WebClient<TResult>().Post(url);
        /// <summary>
        /// Put请求
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="url"></param>
        /// <returns></returns>
        public static IHttpRequest<TResult> Put<TResult>(this string url) where TResult : class => new WebClient<TResult>().Put(url);
        /// <summary>
        /// Delete请求
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="url"></param>
        /// <returns></returns>
        public static IHttpRequest<TResult> Delete<TResult>(this string url) where TResult : class => new WebClient<TResult>().Delete(url);

        /// <summary>
        /// Post请求
        /// </summary>
        /// <param name="urlBuilder"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static IHttpRequest Post<TData>(this UrlBuilder urlBuilder, TData data) where TData : class => new WebClient().Post(urlBuilder.ToString()).JsonData(data);
        /// <summary>
        /// Put请求
        /// </summary>
        /// <param name="urlBuilder"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static IHttpRequest Put<TData>(this UrlBuilder urlBuilder, TData data) where TData : class => new WebClient().Put(urlBuilder.ToString()).JsonData(data);

        /// <summary>
        /// Post请求
        /// </summary>
        /// <param name="url"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static IHttpRequest Post<TData>(this string url, TData data) where TData : class => new WebClient().Post(url).JsonData(data);
        /// <summary>
        /// Put请求
        /// </summary>
        /// <param name="url"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static IHttpRequest Put<TData>(this string url, TData data) where TData : class => new WebClient().Put(url).JsonData(data);

        /// <summary>
        /// Post请求
        /// </summary>
        /// <typeparam name="TData"></typeparam>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="url"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static IHttpRequest<TResult> Post<TData, TResult>(this string url, TData data) where TResult : class where TData : class => new WebClient<TResult>().Post(url).JsonData(data);
        /// <summary>
        /// Put请求
        /// </summary>
        /// <typeparam name="TData"></typeparam>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="url"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static IHttpRequest<TResult> Put<TData, TResult>(this string url, TData data) where TResult : class where TData : class => new WebClient<TResult>().Put(url).JsonData(data);
    }
}